package com.sigerap.ticket.action;

import java.util.List;







import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.sigerap.insumo.model.Insumo;
import com.sigerap.insumo.service.InsumoService;
import com.sigerap.ticket.model.Ticket;
import com.sigerap.ticket.service.TicketService;
/**
 * 
 * @author Spirit-20121
 *
 */
public class GenerarTicketAction extends ActionSupport implements ModelDriven<Ticket>{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Ticket ticket;
	private List<Ticket> tickets;
	private TicketService service;
	private InsumoService service1;
	private List<Insumo> insumos;
	private String mensaje;
	
	public GenerarTicketAction(){
		service=new TicketService();
		service1=new InsumoService();
	}
	
	public String execute()throws Exception{
		String retorno="exito";
		try{
			ticket=service.registrarTicket(ticket);
			mensaje="Ticket generado con exito";
		}catch(Exception ex){
			retorno="sinexito";
			mensaje=ex.getMessage();
		}			
		ticket=service.buscarTicketByNumero(ticket);
		tickets=service.listarTickets();
		insumos=service1.listarInsumos();
		return retorno;
	}

	@Override
	public Ticket getModel() {
		// TODO Auto-generated method stub
		return null;
	}

	public Ticket getTicket() {
		return ticket;
	}

	public void setTicket(Ticket ticket) {
		this.ticket=ticket;
	}

	public String getMensaje() {
		return mensaje;
	}

	public void setMensaje(String mensaje) {
		this.mensaje = mensaje;
	}

	public void setTickets(List<Ticket> tickets) {
		this.tickets = tickets;
	}

	public List<Ticket> getTickets() {
		return tickets;
	}

	public void setInsumos(List<Insumo> insumos) {
		this.insumos = insumos;
	}

	public List<Insumo> getInsumos() {
		return insumos;
	}
	
}
